package rifl.meres4.ui.tracker;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

import rifl.meres4.release.step.ITestStep;
import rifl.meres4.ui.WorkflowUI;

public class TestStepServiceTrackerCustomizer implements ServiceTrackerCustomizer<ITestStep, Object> {

	private final WorkflowUI ui;
	private final BundleContext context;
	
	public TestStepServiceTrackerCustomizer(BundleContext context, WorkflowUI ui)
	{
		this.context = context;
		this.ui= ui;
	}
	
	@Override
	public Object addingService(ServiceReference<ITestStep> reference) {
		ITestStep service = context.getService(reference);
		if (ui != null) {
			ui.setTestStep(service);
		}
		return service;
	}

	@Override
	public void modifiedService(ServiceReference<ITestStep> reference,
			Object service) {		
		
	}

	@Override
	public void removedService(ServiceReference<ITestStep> reference,
			Object service) {
		if (ui != null) {
			ui.unsetTestStep((ITestStep) service);
		}
		
	}

}
